<?php

	require_once CORMO_DIR_CORE.'Object.class.php';
	
	/**
	 * Generador de los WebServices para cada una de las Class del Modelo que se han generado, mediante los
	 * WebServices podremos realizar integraciones de la L�gica de Negocio con otros Lenguajes, Tecnolog�as,
	 * Plataformas y App. ya existentes. Permitiendo una integraci�n de nuestro sistema con el ecosistema.
	 *
   * @category cormo
   * @package Generator
   * @author Germán Dario Peraferrer <gperaferrer@gmail.com>
   * @copyright Copyright (c) 2007 Germán Dario Peraferrer - Beetec
   * @version 1.0 Beta
   * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
   * @link http://code.google.com/p/cormoframework/
   * @link http://www.beetec.com.ar
	 */
	
	class ServiceObject	extends Object {
		
		function __construct($NameObjectORM) {
			return parent::__construct($NameObjectORM);
		}
		
		function __toString() {
			$retun = "";
            $require = "";
			
			/**
			 * Definimos la Class
			 */
			$require .= '  /**'."\n";
			$require .= '   * WebService generado automáticamente cormo.'."\n";
			$require .= '   * '."\n";
			$require .= '   * @category cormo'."\n";
			$require .= '   * @package Service'."\n";
			$require .= '   * @author Germán Dario Peraferrer <gperaferrer@gmail.com>'."\n";
			$require .= '   * @copyright Copyright (c) 2007 Germán Dario Peraferrer - Beetec'."\n";
			$require .= '   * @version 1.0 Beta'."\n";
			$require .= '   * @license http://www.opensource.org/licenses/bsd-license.php New BSD License'."\n";
			$require .= '   * @link http://code.google.com/p/cormoframework/'."\n";
			$require .= '   * @link http://www.beetec.com.ar'."\n";
			$require .= '   */'."\n";
			$require .= "\n";

			/**
			 * Definimos lo Require de la Class
			 */
			
			$require .=	'  require_once "../../config.php";'."\n";
			$require .=	'  require_once CORMO_DIR_CONTROLLER."nusoap/nusoap.php";'."\n";
			$require .=	'  require_once CORMO_DIR_MODEL."'.$this->getConfigObjectName().'.class.php";'."\n";
			$require .=	'  require_once CORMO_DIR_MODEL_QRY."Qry'.$this->getConfigObjectName().'.class.php";'."\n";
			
  		// Definimos los Require de las Class / Tabla Asociadas
			foreach($this->getConfigTableAssociate() as $class => $field)	{
                $require .=	'  require_once CORMO_DIR_MODEL."'.$class.'.class.php";'."\n";
                $require .=	'  require_once CORMO_DIR_MODEL_QRY."Qry'.$class.'.class.php";'."\n";
                // Verificamos si posee Associate de 1:n para incluir las respectivas Class
                if ($field == '1:n') {
                    $require .=	'  require_once CORMO_DIR_MODEL."'.ucwords($this->getConfigObjectName()).$class.'.class.php";'."\n";
                    $require .=	'  require_once CORMO_DIR_MODEL_QRY."Qry'.ucwords($this->getConfigObjectName()).$class.'.class.php";'."\n";
                }
			}
			
			$retun .= "\n";
						
			/**
			 * Creamos la Cabecera del WebService
			 */
			
			$retun .= '  // Creamos la instancia del Servidor.'."\n\n";
			$retun .= '  $server = new soap_server;'."\n";
			$retun .= '  $nameSpace = CORMO_DIR_APP."controller/service/'.$this->getConfigObjectName().'";'."\n";
			$retun .= '  $server->configureWSDL(CORMO_APP_NAME."_'.$this->getConfigObjectName().'", $nameSpace);'."\n";
			$retun .= '  $server->wsdl->schemaTargetNamespace = $nameSpace;'."\n\n";
			
			/**
			 * Definimos el Complex Type Propio
			 */
			
	 		$retun .= '  // Complex Type, representa un solo objeto o registro.'."\n\n";
	 			
			$retun .= '  $server->wsdl->addComplexType("'.ucwords($this->getConfigObjectName()).'",'."\n";
			$retun .= '                                "complexType",'."\n";
			$retun .= '                                "struct",'."\n";
			$retun .= '                                "all",'."\n";
			$retun .= '                                "",'."\n";
			$retun .= '                                array("'.$this->getConfigKey().'" => array("name" => "'.$this->getConfigKey().'", "type" => "xsd:int")';
			foreach($this->getConfigFieldsNotKey() as $field) {
				$retun .= ','."\n";
				$retun .= '                                      "'.$field.'" => array("name" => "'.$field.'", "type" => "xsd:string")';
			}
			$retun .= ' ) );'."\n\n";
			
			/**
			 * Definimos los Complex Type necesarios a partir de los Objetos que se han Asociado
			 */
			
			foreach($this->getConfigTableAssociate() as $class => $field)	{
				$tmpObject = new Object('orm_'.ucwords($class));
				
				$retun .= '  $server->wsdl->addComplexType("'.ucwords($this->getConfigObjectName()).ucwords($tmpObject->getConfigObjectName()).'",'."\n";
				$retun .= '                                "complexType",'."\n";
				$retun .= '                                "struct",'."\n";
				$retun .= '                                "all",'."\n";
				$retun .= '                                "",'."\n";
				$retun .= '                                array("'.$tmpObject->getConfigKey().'" => array("name" => "'.$tmpObject->getConfigKey().'", "type" => "xsd:int")';
				foreach($tmpObject->getConfigFieldsNotKey() as $field) {
					$retun .= ','."\n";
					$retun .= '                                      "'.$field.'" => array("name" => "'.$field.'", "type" => "xsd:string")';
				}
				$retun .= ' ) );'."\n\n";
			}
			
			/**
			 * Definimos el Complex Type Array Propio
			 */
			
	 		$retun .= '  // Complex Type para varios Registros, ideal para utilizar con Grillas o DataSet.'."\n\n";
	 		$retun .= '  $server->wsdl->addComplexType("'.ucwords($this->getConfigObjectName()).'Array",'."\n";
			$retun .= '                                "complexType",'."\n";
			$retun .= '                                "array",'."\n";
			$retun .= '                                "",'."\n";
			$retun .= '                                "SOAP-ENC:Array",'."\n";
			$retun .= '                                array (),'."\n";
			$retun .= '                                array (array ("ref"=>"SOAP-ENC:arrayType",'."\n";
			$retun .= '                                              "wsdl:arrayType"=>"tns:'.ucwords($this->getConfigObjectName()).'") ),'."\n";
			$retun .= '                                "tns:'.ucwords($this->getConfigObjectName()).'");'."\n\n";

			/**
			 * Definimos los Complex Type Array necesarios a partir de los Objetos que se han Asociado
			 */
			
			foreach($this->getConfigTableAssociate() as $class => $field)	{
				$tmpObject = new Object('orm_'.ucwords($class));
				
		 		$retun .= '  $server->wsdl->addComplexType("'.ucwords($this->getConfigObjectName()).ucwords($tmpObject->getConfigObjectName()).'Array",'."\n";
				$retun .= '                                "complexType",'."\n";
				$retun .= '                                "array",'."\n";
				$retun .= '                                "",'."\n";
				$retun .= '                                "SOAP-ENC:Array",'."\n";
				$retun .= '                                array (),'."\n";
				$retun .= '                                array (array ("ref"=>"SOAP-ENC:arrayType",'."\n";
				$retun .= '                                              "wsdl:arrayType"=>"tns:'.ucwords($this->getConfigObjectName()).ucwords($tmpObject->getConfigObjectName()).'") ),'."\n";
				$retun .= '                                "tns:'.ucwords($this->getConfigObjectName()).ucwords($tmpObject->getConfigObjectName()).'");'."\n\n";
			}
			
			/**
			 * Definimos las funciones que poseera el WebService
			 */

	 		$retun .= '  // Registro de Funciones para el WebService.'."\n\n";
	 		
	 		/**
	 		 * Funciones propias
	 		 */
			
			$retun .= '  $server->register("list'.ucwords($this->getConfigObjectName()).'", array(),'."\n";
			$retun .=	'                    array("return" => "tns:'.ucwords($this->getConfigObjectName()).'Array"),'."\n"; 
			$retun .=	'                    $nameSpace);'."\n\n";

			$retun .= '  $server->register("listFilter'.ucwords($this->getConfigObjectName()).'", array("'.strtolower($this->getConfigObjectName()).'" => "tns:'.ucwords($this->getConfigObjectName()).'"),'."\n";
			$retun .=	'                    array("return" => "tns:'.ucwords($this->getConfigObjectName()).'Array"),'."\n";
			$retun .=	'                    $nameSpace);'."\n\n";

			$retun .=	'  $server->register("get'.ucwords($this->getConfigObjectName()).'", array("'.strtolower($this->getConfigKey()).'" => "xsd:int"),'."\n";
			$retun .=	'                    array("return" => "tns:'.ucwords($this->getConfigObjectName()).'"),'."\n";
			$retun .=	'                    $nameSpace);'."\n\n";

			$retun .=	'  $server->register("set'.ucwords($this->getConfigObjectName()).'", array("'.strtolower($this->getConfigObjectName()).'" => "tns:'.ucwords($this->getConfigObjectName()).'"),'."\n";
			$retun .=	'                    array("return" => "xsd:boolean"),'."\n"; 
			$retun .=	'                    $nameSpace);'."\n\n";

			$retun .=	'  $server->register("add'.ucwords($this->getConfigObjectName()).'", array("'.strtolower($this->getConfigObjectName()).'" => "tns:'.ucwords($this->getConfigObjectName()).'"),'."\n";
			$retun .=	'                    array("return" => "xsd:int"),'."\n"; 
			$retun .=	'                    $nameSpace);'."\n\n";

			$retun .=	'  $server->register("del'.ucwords($this->getConfigObjectName()).'", array("'.strtolower($this->getConfigKey()).ucwords($this->getConfigObjectName()).'" => "xsd:int"),'."\n";
			$retun .=	'                    array("return" => "xsd:boolean"),'."\n";
			$retun .=	'                    $nameSpace);'."\n\n";

			$retun .=	'  $server->register("exists'.ucwords($this->getConfigObjectName()).'", array("'.strtolower($this->getConfigObjectName()).'" => "tns:'.ucwords($this->getConfigObjectName()).'"),'."\n";
			$retun .=	'                    array("return" => "xsd:int"),'."\n"; 
			$retun .=	'                    $nameSpace);'."\n\n";

			// Agregamos la definicion de las function por Associate 1:n
			foreach($this->getConfigTableAssociate() as $class => $field)	{
				if ($field == '1:n') {
					$tmpObject = new Object('orm_'.ucwords($class));
					
					$retun .=	'  $server->register("list'.ucwords($this->getConfigObjectName()).ucwords($class).'", array("'.strtolower($this->getConfigKey()).ucwords($this->getConfigObjectName()).'" => "xsd:int"),'."\n";
					$retun .=	'                    array("return" => "tns:'.ucwords($this->getConfigObjectName()).ucwords($class).'Array"),'."\n"; 
					$retun .=	'                    $nameSpace);'."\n\n";
													 					 
					$retun .=	'  $server->register("add'.ucwords($this->getConfigObjectName()).ucwords($class).'", array("'.strtolower($this->getConfigKey()).ucwords($this->getConfigObjectName()).'" => "xsd:int",'."\n";
					$retun .=	'                    "'.strtolower($tmpObject->getConfigKey()).ucwords($class).'" => "xsd:int"),'."\n";
					$retun .=	'                    array("return" => "xsd:boolean"),'."\n"; 
					$retun .=	'                    $nameSpace);'."\n\n";
													 					 
					$retun .=	'  $server->register("del'.ucwords($this->getConfigObjectName()).ucwords($class).'", array("'.strtolower($this->getConfigKey()).ucwords($this->getConfigObjectName()).'" => "xsd:int",'."\n";
					$retun .=	'                    "'.strtolower($tmpObject->getConfigKey()).ucwords($class).'" => "xsd:int"),'."\n";
					$retun .=	'                    array("return" => "xsd:boolean"),'."\n"; 
					$retun .=	'                    $nameSpace);'."\n\n";
					
					$retun .=	'  $server->register("exists'.ucwords($this->getConfigObjectName()).ucwords($class).'", array("'.strtolower($this->getConfigKey()).ucwords($this->getConfigObjectName()).'" => "xsd:int",'."\n";
					$retun .=	'                    "'.strtolower($tmpObject->getConfigKey()).ucwords($class).'" => "xsd:int"),'."\n";
					$retun .=	'                    array("return" => "xsd:boolean"),'."\n"; 
					$retun .=	'                    $nameSpace);'."\n\n";
					
				}
			}
			
			/**
			 * Definimos las funciones que se han declarado
			 */
			
	 		$retun .= '  // Funciones del WebService.'."\n\n";

	 		
			$retun .=	'  function list'.ucwords($this->getConfigObjectName()).'() {'."\n";
			$retun .=	'    $obj = new '.ucwords($this->getConfigObjectName()).'();'."\n";
			$retun .=	'    $arr'.ucwords($this->getConfigObjectName()).' = array();'."\n\n";
			$retun .=	'    foreach(Qry'.ucwords($this->getConfigObjectName()).'::getObjectsAll() as $obj) {'."\n";
			$retun .=	'      $arrReturn = $obj->toArray();'."\n";
			$retun .=	'      array_push($arr'.ucwords($this->getConfigObjectName()).', $arrReturn);'."\n";
			$retun .=	'    }'."\n\n";
			$retun .=	'    return $arr'.ucwords($this->getConfigObjectName()).';'."\n";
			$retun .=	'  }'."\n\n";

			
			$retun .=	'  function listFilter'.ucwords($this->getConfigObjectName()).'($'.strtolower($this->getConfigObjectName()).') {'."\n";
			$retun .=	'    $obj = new '.ucwords($this->getConfigObjectName()).'();'."\n";
			$retun .=	'    $arr'.ucwords($this->getConfigObjectName()).' = array();'."\n";
			$retun .=	'    $properties = array();'."\n";
			$retun .=	'    $lastKey = "";'."\n\n";
			$retun .=	'    if (count($'.strtolower($this->getConfigObjectName()).') > 0) {'."\n";
      $retun .=	'      foreach($'.strtolower($this->getConfigObjectName()).' as $key => $value) {'."\n";
			$retun .=	'        if (strlen($value) > 0) {'."\n";
			$retun .=	'          $properties[$key] = array($value."%", "like", "AND");'."\n";
			$retun .=	'          $lastKey = $key;'."\n";
			$retun .=	'        }'."\n";
			$retun .=	'      }'."\n\n";
			$retun .=	'      if (strlen($lastKey) > 0) {'."\n";
			$retun .=	'        $properties[$lastKey]["2"] = "";'."\n";
			$retun .=	'      }'."\n\n";
      $retun .=	'      foreach(Qry'.ucwords($this->getConfigObjectName()).'::getObjectsByProperty($properties) as $obj) {'."\n";
			$retun .=	'        $arrReturn = $obj->toArray();'."\n";
			$retun .=	'        array_push($arr'.ucwords($this->getConfigObjectName()).', $arrReturn);'."\n";
			$retun .=	'      }'."\n\n";
			$retun .=	'    } else {'."\n";
			$retun .=	'      $arr'.ucwords($this->getConfigObjectName()).' = list'.ucwords($this->getConfigObjectName()).'();'."\n";
			$retun .=	'    }'."\n\n";
      $retun .=	'    return $arr'.ucwords($this->getConfigObjectName()).';'."\n";
			$retun .=	'  }'."\n\n";


			$retun .=	'  function get'.ucwords($this->getConfigObjectName()).'($'.strtolower($this->getConfigKey()).') {'."\n";
			$retun .=	'    $obj = new '.ucwords($this->getConfigObjectName()).'($'.strtolower($this->getConfigKey()).');'."\n";
			$retun .=	'    $arrReturn = $obj->toArray();'."\n";
			$retun .=	'    return $arrReturn;'."\n";
			$retun .=	'  }'."\n\n";

			
			$retun .=	'  function set'.ucwords($this->getConfigObjectName()).'($'.strtolower($this->getConfigObjectName()).') {'."\n";
			$retun .=	'    $obj = new '.ucwords($this->getConfigObjectName()).'($'.strtolower($this->getConfigObjectName()).'['.$this->getConfigKey().']);'."\n\n";
			$retun .=	'    if ($obj->isValid()) {'."\n";
			// Agregamos los property del Objeto
			// En array_diff quitamos los property que estan asociados
			foreach(array_diff($this->getConfigFieldsNotKey(), $this->getConfigTableAssociate()) as $property) {
				$retun .=	'      $obj->set'.ucwords($property).'($'.strtolower($this->getConfigObjectName()).'['.$property.']);'."\n";
			}
			// Agregamos los Objetc relacionados 1:1
			foreach($this->getConfigTableAssociate() as $class => $field)	{
				if ($field != '1:n') {
					$retun .=	'      $obj->set'.ucwords($class).'(new '.ucwords($class).'($'.strtolower($this->getConfigObjectName()).'['.$field.']));'."\n";
				}
			}
			$retun .=	'      return $obj->save();'."\n";
			$retun .=	'    } else {'."\n";
			$retun .=	'      return false;'."\n";
			$retun .=	'    }'."\n";
			$retun .=	'  }'."\n\n";

			
			$retun .=	'  function add'.ucwords($this->getConfigObjectName()).'($'.strtolower($this->getConfigObjectName()).') {'."\n";
			$retun .=	'    $obj = new '.ucwords($this->getConfigObjectName()).'();'."\n";
			// Creamos los Objetc relacionados 1:1
			foreach($this->getConfigTableAssociate() as $class => $field)	{
				if ($field != '1:n') {
					$retun .=	'    $'.strtolower($class).' = new '.ucwords($class).'($'.strtolower($this->getConfigObjectName()).'['.$field.']);'."\n";
				}
			}
			// Creamos el Condicional para los Objetc relacionados 1:n
			$conditional = '';
			foreach($this->getConfigTableAssociate() as $class => $field)	{
				if ($field != '1:n') {
					$conditional .= ' ($'.strtolower($class).'->isValid()) &&'; 
				}
			}
			$conditional = substr($conditional, 0, strlen($conditional)-2);
			// Colocamos el conditional en true en el caso de que no posee property associate
			if (strlen($conditional) < 2) {
				$conditional = 'true';
			}
			// Creamos los parametros para el Add
			$parameters = '';
			foreach($this->getConfigFieldsNotKey() as $property) {
				// Controlamos si se trata de un property associate
				if (!in_array($property, $this->getConfigTableAssociate())) {
					$parameters .= '$'.strtolower($this->getConfigObjectName()).'['.$property.'], '; 
				} else {
					$parameters .= '$'.strtolower(array_search($property, $this->getConfigTableAssociate())).', ';
				}
			}
			$parameters = substr($parameters, 0, strlen($parameters)-2);
			$retun .=	"\n";
			$retun .=	'    if ('.$conditional.') {'."\n";
			$retun .=	'      if ($obj->add('.$parameters.')) {'."\n";
			$retun .=	'        return $obj->get'.$this->getConfigKey().'();'."\n";
			$retun .=	'      }'."\n";
			$retun .=	'    } else {'."\n";
			$retun .=	'      return 0;'."\n";
			$retun .=	'    }'."\n";
			$retun .=	'  }'."\n\n";

			
			$retun .=	'  function del'.ucwords($this->getConfigObjectName()).'($'.strtolower($this->getConfigKey()).ucwords($this->getConfigObjectName()).') {'."\n";
			$retun .=	'    $obj = new '.ucwords($this->getConfigObjectName()).'($'.strtolower($this->getConfigKey()).ucwords($this->getConfigObjectName()).');'."\n\n";
			$retun .=	'    if ($obj->isValid()) {'."\n";
			$retun .=	'      return $obj->delete();'."\n";
			$retun .=	'    } else {'."\n";
			$retun .=	'      return false;'."\n";
			$retun .=	'    }'."\n";
			$retun .=	'  }'."\n\n";
			
			
			$retun .=	'  function exists'.ucwords($this->getConfigObjectName()).'($'.strtolower($this->getConfigObjectName()).') {'."\n";
			$retun .=	'    $obj = new '.ucwords($this->getConfigObjectName()).'();'."\n\n";
			// Agregamos los property del Objeto
			// En array_diff quitamos los property que estan asociados
			foreach(array_diff($this->getConfigFieldsNotKey(), $this->getConfigTableAssociate()) as $property) {
				$retun .=	'    $obj->set'.ucwords($property).'($'.strtolower($this->getConfigObjectName()).'['.$property.']);'."\n";
			}
			// Agregamos los Objetc relacionados 1:1
			foreach($this->getConfigTableAssociate() as $class => $field)	{
				if ($field != '1:n') {
					$retun .=	'    $obj->set'.ucwords($class).'(new '.ucwords($class).'($'.strtolower($this->getConfigObjectName()).'['.$field.']));'."\n";
				}
			}
			$retun .= "\n";
			$retun .=	'    return $obj->exists();'."\n";		
			$retun .=	'  }'."\n\n";

			
			// Agregamos las function por Associate 1:n
			foreach($this->getConfigTableAssociate() as $class => $field)	{
				if ($field == '1:n') {
					$tmpObject = new Object('orm_'.ucwords($class));
					
					$retun .=	'  function list'.ucwords($this->getConfigObjectName()).ucwords($class).'($'.strtolower($this->getConfigKey()).ucwords($this->getConfigObjectName()).') {'."\n";
					$retun .=	'    $obj = new '.ucwords($this->getConfigObjectName()).'($'.strtolower($this->getConfigKey()).ucwords($this->getConfigObjectName()).');'."\n";
					$retun .=	'    $'.strtolower($class).' = new '.ucwords($class).'();'."\n";
					$retun .=	'    $arr'.ucwords($class).' = array();'."\n\n";
					$retun .=	'    foreach($obj->list'.ucwords($class).'() as $'.strtolower($class).') {'."\n";
					$retun .=	'      $arrReturn = $'.strtolower($class).'->toArray();'."\n";
					$retun .=	'      array_push($arr'.ucwords($class).', $arrReturn);'."\n";
					$retun .=	'    }'."\n\n";
					$retun .=	'    return $arr'.ucwords($class).';'."\n";
					$retun .=	'  }'."\n\n";

					$retun .=	'  function add'.ucwords($this->getConfigObjectName()).ucwords($class).'($'.strtolower($this->getConfigKey()).ucwords($this->getConfigObjectName()).', $'.strtolower($tmpObject->getConfigKey()).ucwords($class).') {'."\n";
					$retun .=	'    $obj = new '.ucwords($this->getConfigObjectName()).'($'.strtolower($this->getConfigKey()).ucwords($this->getConfigObjectName()).');'."\n";
					$retun .=	'    $'.strtolower($class).' = new '.ucwords($class).'($'.strtolower($tmpObject->getConfigKey()).ucwords($class).');'."\n\n";
					$retun .=	'    if ($obj->isValid() && $'.strtolower($class).'->isValid()) {'."\n";
					$retun .=	'      return $obj->add'.ucwords($class).'($'.strtolower($class).');'."\n";
					$retun .=	'    } else {'."\n";
					$retun .=	'      return false;'."\n";
					$retun .=	'    }'."\n";
					$retun .=	'  }'."\n\n";
					
					$retun .=	'  function del'.ucwords($this->getConfigObjectName()).ucwords($class).'($'.strtolower($this->getConfigKey()).ucwords($this->getConfigObjectName()).', $'.strtolower($tmpObject->getConfigKey()).ucwords($class).') {'."\n";
					$retun .=	'    $obj = new '.ucwords($this->getConfigObjectName()).'($'.strtolower($this->getConfigKey()).ucwords($this->getConfigObjectName()).');'."\n";
					$retun .=	'    $'.strtolower($class).' = new '.ucwords($class).'($'.strtolower($tmpObject->getConfigKey()).ucwords($class).');'."\n\n";
					$retun .=	'    if ($obj->isValid() && $'.strtolower($class).'->isValid()) {'."\n";
					$retun .=	'      return $obj->del'.ucwords($class).'($'.strtolower($class).');'."\n";
					$retun .=	'    } else {'."\n";
					$retun .=	'      return false;'."\n";
					$retun .=	'    }'."\n";
					$retun .=	'  }'."\n\n";
					
					$retun .=	'  function exists'.ucwords($this->getConfigObjectName()).ucwords($class).'($'.strtolower($this->getConfigKey()).ucwords($this->getConfigObjectName()).', $'.strtolower($tmpObject->getConfigKey()).ucwords($class).') {'."\n";
					$retun .=	'    $obj = new '.ucwords($this->getConfigObjectName()).'($'.strtolower($this->getConfigKey()).ucwords($this->getConfigObjectName()).');'."\n";
					$retun .=	'    $'.strtolower($class).' = new '.ucwords($class).'($'.strtolower($tmpObject->getConfigKey()).ucwords($class).');'."\n\n";
					$retun .=	'    if ($obj->isValid() && $'.strtolower($class).'->isValid()) {'."\n";
					$retun .=	'      return $obj->exists'.ucwords($class).'($'.strtolower($class).');'."\n";
					$retun .=	'    } else {'."\n";
					$retun .=	'      return false;'."\n";
					$retun .=	'    }'."\n";
					$retun .=	'  }'."\n\n";
					
				}
			}
			
			/**
			 * Cerramos el WebService
			 */
			
			$retun .= '  @$server->service($HTTP_RAW_POST_DATA);'."\n"; 
			
			return $require.$retun;
		}

	}
	
?>